package com.znjc.device.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.znjc.device.domain.IotDataResRule;
import com.znjc.device.mapper.IotDataResRuleMapper;
import com.znjc.device.service.IIotDataCheckRuleRefService;
import com.znjc.device.service.IIotDataResRuleService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * 【请填写功能名称】Service业务层处理
 *
 * @author zengpc
 * @date 2023-12-04
 */
@Service
public class IotDataResRuleServiceImpl extends ServiceImpl<IotDataResRuleMapper, IotDataResRule> implements IIotDataResRuleService {

    @Resource
    IIotDataCheckRuleRefService iotDataCheckRuleRefService;

    @Override
    public List<IotDataResRule> getRules(Long checkId) {
        List<Long> rulesId = iotDataCheckRuleRefService.getIdList(checkId, 1);
        if (CollectionUtils.isEmpty(rulesId)) {
            return null;
        }
        LambdaQueryWrapper<IotDataResRule> wrapper = new LambdaQueryWrapper<>();
        wrapper.in(IotDataResRule::getId, rulesId);
        return this.list(wrapper);
    }

    @Override
    public List<IotDataResRule> getListByTypeId(Long typeId) {
        LambdaQueryWrapper<IotDataResRule> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(IotDataResRule::getStatus, "0");
        queryWrapper.eq(IotDataResRule::getDelFlag, "0");
        queryWrapper.eq(IotDataResRule::getTypeId, typeId);
        return this.list(queryWrapper);
    }
}
